﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;

public partial class adminstrator_editPatientStart : System.Web.UI.Page
{
    public int stuID;
    public OleDbConnection myConnection;
    public static readonly string sconnectionstring = System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        myConnection = new OleDbConnection(sconnectionstring);
        myConnection.Open();
        if (Session["UserName"] == null && Session["UserNo"] == null)
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>" +
                "alert('登录超时（或未登录），请您重新登录！'); parent.location.href='../login.aspx'</script>", false);
        stuID = int.Parse(Request.QueryString["stuID"]);
        if (!IsPostBack)
            bind(stuID);
    }
    protected void ButtonOK_Click(object sender, EventArgs e)
    {
        string sSex;
        if (RadioButtonMan.Checked == true)
            sSex = "男";
        else
            sSex = "女";
        string mystr1 = "update PatTb set Name='" + UserName.Text.Trim() + "', Addresss='" + Useradd.Text.Trim() + "', Type='" + Usertype.Text.Trim() + "', Age='" + Userage.Text.Trim() + "',Sex='" + sSex + "',Phone='" + TELL.Text.Trim() + "',ID_JZ='" +
            UserNo.Text.Trim() + "',Snum='" + Usernum.Text.Trim() + "' where ID=" + stuID + " ";
        OleDbCommand mycmd1 = new OleDbCommand(mystr1, myConnection);
        mycmd1.ExecuteNonQuery();
        string mystr2 = "update GH set Name='" + UserName.Text.Trim() + "', Type='" + Usertype.Text.Trim() + "', Age='" + Userage.Text.Trim() + "',Sex='" + sSex + "',ID_JZ='" +
            UserNo.Text.Trim() + "' where ID_JZ='" + UserNo.Text.Trim() + "' ";
        OleDbCommand mycmd2= new OleDbCommand(mystr2, myConnection);
        mycmd2.ExecuteNonQuery();
        Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('病人信息修改成功!');</script>", false);
    }
    protected void ButtonReset_Click(object sender, EventArgs e)
    {
        bind(stuID);
    }

    public void bind(int id)
    {
        string mysql = "select * from PatTb where ID="+ id +" " ;
        OleDbCommand mycmd = new OleDbCommand(mysql, myConnection);
        OleDbDataReader myReader = mycmd.ExecuteReader();
        if (myReader.Read())
        {
            UserNo.Text = myReader[1].ToString();
            UserName.Text = myReader[2].ToString();
            if (myReader[3].ToString() == "男")
            {
                RadioButtonMan.Checked = true;
                RadioButtonWoman.Checked = false;
            }
            else
            {
                RadioButtonMan.Checked = false;
                RadioButtonWoman.Checked = true;
            }
        }
        else
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('操作有误！'); location.href='editPatient.aspx'</script>", false);
    }
}